local kaicang = fk.CreateSkill {
  name = "lingling__kaicang",
}

Fk:loadTranslationTable{
  ["lingling__kaicang"] = "开仓",
  [":lingling__kaicang"] = "当你使用【杀】对其他角色造成伤害后，你可以令其将两张牌置于牌堆顶，然后其视为使用【五谷丰登】。",

  ["#lingling__kaicang-invoke"] = "开仓：你可以令 %dest 将两张牌置于牌堆顶，其视为使用【五谷丰登】",
  ["#lingling__kaicang-ask"] = "开仓：请将两张牌置于牌堆顶，视为使用【五谷丰登】",
}

kaicang:addEffect(fk.Damage, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(kaicang.name) and
      data.to ~= player and data.card and data.card.trueName == "slash" and
      #data.to:getCardIds("he") > 1 and data.to:isAlive()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = kaicang.name,
      prompt = "#lingling__kaicang-invoke::"..data.to.id,
    }) then
      event:setCostData(self, {tos = {data.to}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(data.to, {
      min_num = 2,
      max_num = 2,
      include_equip = true,
      skill_name = kaicang.name,
      prompt = "#lingling__kaicang-ask",
      cancelable = false,
    })
    room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, kaicang.name, nil, false, data.to)
    local card = Fk:cloneCard("amazing_grace")
    card.skillName = kaicang.name
    if not data.to.dead and data.to:canUse(card) then
      room:useVirtualCard("amazing_grace", nil, data.to, card:getAvailableTargets(data.to), kaicang.name)
    end
  end,
})

return kaicang
